<style lang="sass" scoped>
    .img{
        width:120px;
    }
</style>
<template>
    <div  class="container">
        <div class="search-cont">
            <el-input placeholder="请搜索" v-model.trim="search.keyWord">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
            <el-button @click="getList()" type="primary" :plain="false">搜索</el-button>
            <el-button @click="routerGo('dis_add')" type="primary" :plain="false">新增</el-button>
        </div>
        <div class="tabs-cont">
            <el-button
                @click="search.isFree=''" 
                :type="search.isFree===''?'primary':''">全部</el-button>
            <el-button
                @click="search.isFree=0" 
                :type="search.isFree===0?'primary':''">待冻结</el-button>
            <el-button
                @click="search.isFree=1" 
                :type="search.isFree===1?'primary':''">已冻结</el-button>
        </div>
        <div class="table-cont">
            <el-table :data="list" style="width: 100%">
                <el-table-column prop="companyCode" label="分销商编码">
                </el-table-column>
                <el-table-column prop="companyName" label="分销商名称">
                </el-table-column>
                <el-table-column prop="contact" label="联系人">
                </el-table-column>
                <el-table-column prop="contactPhone" label="联系人电话">
                </el-table-column>
                <el-table-column label="提成比例">
                    <template slot-scope="props">
                        {{props.row.commissionRate}}%
                    </template>
                </el-table-column>
                <el-table-column prop="withdrawalFee" label="累计提现金额">
                </el-table-column>
                <el-table-column width="260" label="操作">
                    <template slot-scope="props">
                        <el-button @click="routerGo('dis_edit',{companyCode:props.row.companyCode})" type="primary" :plain="false" size="small">修改</el-button>
                        <el-button v-if="props.row.status === 0" @click="modifyStatus()" type="primary" :plain="false" size="small">冻结</el-button>
                        <el-button v-if="props.row.status === 1" @click="modifyStatus()" type="primary" :plain="false" size="small">解冻</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination background layout="total, prev, pager, next" :total="search.total" @current-change="handleCurrentChange">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    export default {
        components: {
        },
        data() {
            return {
                //列表搜索参数
                search:{
                    keyWord:'',//	是	string	搜索关键字
                    isFree:'',//	是	string	状态，0-正常，1-已冻结
                    pageNo:1, //	是	string	页码
                    pageSize:config.pageSize, //	是	string	当前页显示的条数
                    total:0,
                },
                list:[],
            };
        },
        watch:{
            'search.isFree'(val){
                this.getList();
            }
        },
        created(){
        },
        mounted() {
            this.$nextTick(() => {
                this.getList();
            });
        },
        methods: {
            handleCurrentChange(val) {
                this.search.pageNo = val;
                this.getList();
            },
            getList() {
                let param = JSON.parse(JSON.stringify(this.search));
                util.ajax({
                    url: config.baseApi + "bookMall-admin/api/company/getCompanyListPage",
                    data: param,
                    success: data => {
                        this.list = data.data.record;
                        this.search.total = data.data.totalNum;
                    }
                });
            },
            modifyStatus(item){
                let content = '',
                    success = '';
                if(item.status===0){
                    content = '是否冻结该分销商？';
                    success = '冻结成功！';
                }else{
                    content = '是否解冻该分销商？';
                    success = '解冻成功！';
                }
                popup.confirm({
                    content:content,
                    yes:()=>{
                        util.ajax({
                            url:config.baseApi + 'bookMall-admin/api/item/modifyStatus',
                            data:{
                                itemCode:item.itemCode,	//是	string	商品编码
                                status:item.status===0?1:0,	//是	string	状态，0-未冻结，1-已冻结
                            },
                            success:()=>{
                                popup.miss({
                                    content:success
                                });
                                this.getList();
                            }
                        })
                    }
                })
            },
        },
        
    };
</script>